package text
import (
"fmt"
"github.com/K-Phoen/grabana/errors"
"github.com/K-Phoen/grabana/links"
"github.com/K-Phoen/sdk"
)
type Option func (text *Text ) error
type Text struct {
Builder *sdk .Panel
}
func New (title string , options ...Option ) (*Text , error ) {
panel := &Text {Builder : sdk .NewText (title )}
panel .Builder .IsNew = false
panel .Builder .Span = 6
for _ , opt := range options {
if err := opt (panel ); err != nil {
return nil , err
}
}
return panel , nil
}
func Links (panelLinks ...links .Link ) Option {
return func (text *Text ) error {
text .Builder .Links = make ([]sdk .Link , 0 , len (panelLinks ))
for _ , link := range panelLinks {
text .Builder .Links = append (text .Builder .Links , link .Builder )
}
return nil
}
}
func HTML (content string ) Option {
return func (text *Text ) error {
text .Builder .TextPanel .Mode = "html"
text .Builder .TextPanel .Content = content
return nil
}
}
func Markdown (content string ) Option {
return func (text *Text ) error {
text .Builder .TextPanel .Mode = "markdown"
text .Builder .TextPanel .Content = content
return nil
}
}
func Span (span float32 ) Option {
return func (text *Text ) error {
if span < 1 || span > 12 {
return fmt .Errorf ("span must be between 1 and 12: %w" , errors .ErrInvalidArgument )
}
text .Builder .Span = span
return nil
}
}
func Height (height string ) Option {
return func (text *Text ) error {
text .Builder .Height = &height
return nil
}
}
func Description (content string ) Option {
return func (text *Text ) error {
text .Builder .Description = &content
return nil
}
}
func Transparent () Option {
return func (text *Text ) error {
text .Builder .Transparent = true
return nil
}
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .